package com.fy.common.util;

import java.io.File;
import java.io.FileOutputStream;

/**
 * @author huangming
 * @Description
 * @create 2019-04-29 17:42
 */
public class FileUtil {

    /**
     * 上传文件
     * @param file
     * @param filePath
     * @param fileName
     * @return
     * @throws Exception
     */
    public static String uploadFile (byte[] file, String filePath, String fileName) throws Exception {
        File targetFile = new File(filePath);
        if (!targetFile.exists()) {
            targetFile.mkdir();
        }
        FileOutputStream out = new FileOutputStream(filePath + fileName);
        out.write(file);
        out.flush();
        out.close();
        return filePath + fileName;
    }


    /**
     * 取得文件后缀
     * @param path
     * @return
     */
    public static String getPostfix(String path) {
        String postfix = "";
        if (path != null && !path.isEmpty()) {
            if (path.contains(".")) {
                return path.substring(path.lastIndexOf(".") + 1, path.length());
            }
        }
        return postfix;
    }
}
